<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head th:include="common/header"></head>
<body>
	<div class="layui-fluid">

		<!-- 导航菜单 -->
		<div th:replace="common/system/system_fragment :: system_menu('系统管理')"></div>

		<!-- 当前位置 -->
		<div th:replace="common/system/system_fragment :: system_location('系统管理', '角色管理')"></div>
		
		<div class="layui-row yy-margin-top-10">
			<!-- 查询 -->
			<div class="layui-collapse" lay-accordion="lay-accordion">
				<div class="layui-colla-item">
					<h2 class="layui-colla-title">查询</h2>
					<div class="layui-colla-content layui-show">
						<div class="layui-form layui-form-pane">
							<div class="layui-form-item">
								<label class="layui-form-label layui-bg-orange">角色名称</label>
								<div class="layui-input-block">
									<input type="text" name="name" autocomplete="off" class="layui-input">
								</div>
							</div>
							
							<!-- 查询按钮 -->
							<div class="layui-form-item">
								<div class="layui-input-block">
									<button class="layui-btn yy-float-right" onclick="queryRole();">查询</button>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		
		<div class="layui-row">
			
			<a class="layui-btn yy-margin-top-10" th:href="@{'/role/roleform/-1'}" th:each="str,iterStat:${USER_PERMISSION_KEY}" th:if="${str eq 'role:add'}">
				<i class="layui-icon">&#xe654;</i> 添加
			</a>
			
			<a class="layui-btn yy-margin-top-10" th:each="str,iterStat:${USER_PERMISSION_KEY}" th:if="${str eq 'role:update'}" onclick="editRole();">
				<i class="layui-icon">&#xe642;</i> 编辑
			</a>
			
			<a class="layui-btn layui-btn-danger yy-margin-top-10" th:each="str,iterStat:${USER_PERMISSION_KEY}" th:if="${str eq 'role:delete'}" onclick="delRole();">
				<i class="layui-icon">&#xe640;</i> 删除
			</a>
			
			<!-- 表格 -->
			<table id="roleTable" class="yy-margin-top-10"></table>
		</div>
		
	</div>

	<!-- 引入js -->
	<div th:replace="common/script"></div>
	
	<script th:inline="none">
	/*<![CDATA[*/
	
	var tableObj;
	var table;
	
	//查询
	var queryRole = function(){
		
		var name = $("input[name=name]").val();
		
		tableObj.reload({
			where:{
				name:name
			}
		});
	};
		
	;!function(){
		
		table = layui.table;
		
		tableObj = table.render({
			elem:"#roleTable",
			id:"roleTable",
			loading:true,
			url:"/role/roleTable",
			skin:"line",
			even:true,
			cols:[[
				{field:"id", title:"id", width:0, fixed:'left', checkbox:true},
				{field:"name", title:"角色名称", width:200},
				{field:"seq", title:"顺序", width:70},
				{field:"includepermissions", title:"包含权限", width:500}
			]],
			page:true,
			height:'full',//自适应高度，数据多高表格多高
			limits:[10,30,50,100],
			limit:10,
			size:'lg'
		});
		
	}();
	
	//查看
	function show(id){
		var checkStatus = table.checkStatus('roleTable');
		if(checkStatus.data.length <= 0 || checkStatus.data.length > 1){
			$.prompt.alert("请选择并且只能选择一条数据!");
			return;
		}
		$.logs.info(checkStatus);
		var id = checkStatus.data[0].id;
		var href="/role/show/"+id;
		window.location.href=href;
	}
	
	//分配权限
	function assignPermission(){
		var checkStatus = table.checkStatus('roleTable');
		if(checkStatus.data.length <= 0 || checkStatus.data.length > 1){
			$.prompt.alert("请选择并且只能选择一条数据!");
			return;
		}
		var id = checkStatus.data[0].id;
		
	}
	
	//编辑
	function editRole(){
		var checkStatus = table.checkStatus('roleTable');
		if(checkStatus.data.length <= 0){
			$.prompt.alert("请选择并且只能选择一条数据!" || checkStatus.data.length > 1);
			return;
		}
		var id = checkStatus.data[0].id;
		var href="/role/roleform/"+id;
		window.location.href=href;
	}
	
	//删除
	function delRole(){
		var checkStatus = table.checkStatus('roleTable');
		if(checkStatus.data.length <= 0 || checkStatus.data.length > 1 ){
			$.prompt.alert("请选择并且只能选择一条数据!" || checkStatus.data.length > 1);
			return;
		}
		var id = checkStatus.data[0].id;
		$.prompt.delPromptBox("确定要删除吗？", "/role/delrole/"+id, tableObj);
	}
	
	/*]]>*/
	</script>

</body>

</html>